package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface DishMapper {
    /*
    * 根据分类id查询菜品数量
    * */
    @Select("SELECT count(id) FROM dish WHERE category_id = #{categoryId}")
    Integer getDishCountByCategoryId(Long categoryId);

    /*
    * 新增菜品
    * */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /*
    * 分页查询
    * */
    Page<DishVO> pageSelect(DishPageQueryDTO dishPageQueryDTO);

    /*
    * 查询是否有在售状态的菜品
    * */
    Integer onSaleCount(List<Long> ids);

    /*
    * 删除菜品
    * */
    void delete(List<Long> ids);

    /*
    * 根据id查询菜品详情
    * */
    @Select("SELECT * FROM dish WHERE id = #{id}")
    DishVO getDishById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);
    /*
    * 根据分类id查询起售状态菜品
    * */
    @Select("SELECT * FROM dish WHERE category_id = #{categoryId} AND status = #{status}")
    List<DishVO> selectDishByCategoryId(Integer categoryId,Integer status);
    /*
     * 根据分类ID修改菜品状态
     * */
    @Update("UPDATE dish SET status = #{status},update_time = #{updateTime},update_user = #{updateUser} WHERE category_id = #{categoryId}")
    void updateStatusByCategoryId(Long categoryId, Integer status, LocalDateTime updateTime,Long updateUser);

    @Select("SELECT COUNT(id) FROM dish WHERE status = #{status}")
    Integer getDishStatusCount(Integer status);
}
